#ifndef _CUTSCENE_H_
#define _CUTSCENE_H_

#include "background/bg_scene.h"
#include "script/state_holder.h"
namespace gameflow
{
class CutsceneTransition;
class Cutscene : script::StateHolder
{
public:
	struct	CutSceneData
	{
		std::string		Name;
		std::string		BGScene;
		std::string		Text;
		std::string		Title;
		math::Vec2		From, To;
		std::string		EnterEffect;
		std::string		ExitEffect;
		float			PanDuration;
		float			SceneDuration;
		std::string		Next;
		std::string		Prev;
		std::string		Voiceover;
		float			ScaleDuration;
		float			ScaleFrom, ScaleTo;
		int				AutoAdvance;
	};

	Cutscene();
	virtual				~Cutscene();

	virtual	void		Reload(const std::string& File);
	virtual	void		Init();
	virtual	bool		Tick(float dt);
	virtual	bool		Render();
	
	//control funcs
	virtual	void		ClearScreen();
	virtual	bool		SetPage(const std::string& scene);
	virtual	bool		NextPage();
	virtual bool		PrevPage();
	virtual	void		EndScene();

	void					GetStartPoints(std::vector<std::string>& List);


// accessors
	bool					IsInTransition() const {return m_pEntryTransition || m_pExitTransition || m_pQueuedScene; };
	background::BGScene&	GetBGScene() { return m_Background; };
	CutSceneData*			GetCurrentSceneData() { return m_pCurrentScene; }
	ui::UIWidget*			GetUI() { return m_pUIPanel; };

protected:	
	virtual void		RenderCache(ImageCache* pCache, float x, float y, bool blend);	
	virtual void		UpdateStoryText(const std::string& StoryText, const std::string& StoryTitle = "");
	virtual void		SetOffset(float from_x, float from_y);
	virtual void		Refresh(bool ResetBg);

	// empty functions designed for overriding
	virtual void		CustomLoad(LuaPlus::LuaObject& Obj) { };
	virtual void		OnTransitionComplete(CutsceneTransition* pCutscene) {};

	// behaviour functions designed for overriding
	virtual const char*	GetBlankImg() const { return "ui_img/blank_cutscene.jpg"; };

	ImageCache*					m_pCache;
	std::vector<CutSceneData*>	m_CutSceneData;
	ui::UIWidget*				m_pUIPanel;
	ui::UIWidget*				m_pUIStoryTitle;
	ui::UIWidget*				m_pUIStoryText;
	ui::UIWidget*				m_pUIStoryTextBG;
	ui::UIWidget*				m_pUIStoryControls;
	ui::UIWidget*				m_pUIStoryNext;
	ui::UIWidget*				m_pUIStorySkip;
	ui::UIWidget*				m_pUIStoryBack;
	CutsceneTransition*			m_pEntryTransition;
	CutsceneTransition*			m_pExitTransition;
	CutSceneData*				m_pCurrentScene;	
	CutSceneData*				m_pQueuedScene;	

	background::BGScene			m_Background;
	float						m_FrameTime;
	float						m_ForegroundScale;
	float						m_BackgroundScale;
};
}//namespace gameflow

#endif